import React, {Component} from 'react';
import './index.css'
import Item from "../Item";
import PropTypes from 'prop-types'

class List extends Component {
    //对接收的props类型和必要性的限制
    static propTypes = {
        todos: PropTypes.array.isRequired,
        changeTodo: PropTypes.func.isRequired,
        deleteTodo: PropTypes.func.isRequired,
    }

    render() {
        let {todos, changeTodo, deleteTodo} = this.props;
        return (
            <ul className="todo-main">
                {
                    todos.map((todo) => {
                        return <Item changeTodo={changeTodo}
                                     deleteTodo={deleteTodo}
                                     key={todo.id} {...todo}/>
                    })
                }
            </ul>
        );
    }
}

export default List;